package worldinruin.gui.imp.gameview.gameboard;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JButton;

import worldinruin.core.ITile;
import worldinruin.core.ITroop;
import worldinruin.resources.Panels;

public class TroopPiece extends JButton implements ITilePiece {
	
	private ITroop troop;
	private Panels mainPanelType = Panels.GAMEVIEWMAINPANEL;
	private Panels cardStack = Panels.GAMEVIEWLEFTCARDSTACK;
	private Panels subPanelType = Panels.TROOPPANEL;
	private int flagPoleHeight = 12;
	private int flagPoleWidth = 2;
	private int flagWidth = 14;
	private int flagHeight = 8;
	private int flagX = 5;
	private int flagY = 5;

	/**
	 * Creates a troop piece to display on gameboard.
	 * @param troop Troop to display.
	 */
	public TroopPiece(ITroop troop) {
		this.troop = troop;
		setPreferredSize(new Dimension(20, 30));
		setBorderPainted(false);
	}
	
	/**
	 * Creates a troop piece.
	 */
	public TroopPiece() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void paintComponent(Graphics g){
		g.setColor(troop.getPlayer().getColor());		
		g.fillRect(flagX, flagY, flagWidth, flagHeight);
		g.setColor(Color.black);
		g.fillRect(flagX, flagY + flagHeight, flagPoleWidth, flagPoleHeight);
		g.drawRect(flagX, flagY, flagWidth, flagHeight);
	}

	@Override
	public Object getPieceModel() {
		return troop;
	}
	
	@Override
	public ITile getTileModel() {
		return troop.getPosition();
	}

	@Override
	public Panels getMainPanelType() {
		return mainPanelType;
	}

	@Override
	public Panels getCardStack() {
		return cardStack;
	}

	@Override
	public Panels getSubPanelType() {
		return subPanelType;
	}
}
